﻿using QDP.Platform.Services;

public static class LoggerExtensions
{
    private static ILoggerService logger = null;
    public static ILoggerService GetLogger<T>(this T me) where T : class
    {
        if (logger == null)
        {
            logger = ServiceLoader.Load<ILoggerService>();
        }
        return logger;
    }
    public static void Debug<T>(this T me, string format, params object[] args) where T : class
    {
        if (logger == null) GetLogger(me);
        if (logger == null) return;
        logger.Debug(me.GetType().FullName,format,args);
    }
    public static void Error<T>(this T me, string format, params object[] args) where T : class
    {
        if (logger == null) GetLogger(me);
        if (logger == null) return;
        logger.Error(me.GetType().FullName, format, args);
    }
    public static void Fatal<T>(this T me, string format, params object[] args) where T : class
    {
        if (logger == null) GetLogger(me);
        if (logger == null) return;
        logger.Fatal(me.GetType().FullName, format, args);
    }
    public static void Info<T>(this T me, string format, params object[] args) where T : class
    {
        if (logger == null) GetLogger(me);
        if (logger == null) return;
        logger.Info(me.GetType().FullName, format, args);
    }
    public static void Warn<T>(this T me, string format, params object[] args) where T : class
    {
        if (logger == null) GetLogger(me);
        if (logger == null) return;
        logger.Warn(me.GetType().FullName, format, args);
    }
    /// <summary>设置日志记录内容</summary>
    /// <param name="IsDebug">一个值，指定日志记录器是否记录Debug</param>
    /// <param name="IsInfo">一个值，指定日志记录器是否记录Info</param>
    /// <param name="IsWarn">一个值，指定日志记录器是否记录Warn</param>
    /// <param name="IsFatal">一个值，指定日志记录器是否记录Fatal</param>
    /// <param name="IsError">一个值，指定日志记录器是否记录Error</param>
    public static void LoggerOption<T>(this T me, bool IsDebug = false, bool IsInfo = false, bool IsWarn = false, bool IsFatal = false, bool IsError = false) where T : class
    {
        if (logger == null)
        {
            GetLogger(me);
        }
        if (logger != null)
        {
            logger.IsDebug = IsDebug;
            logger.IsFatal = IsFatal;
            logger.IsWarn = IsWarn;
            logger.IsInfo = IsInfo;
            logger.IsError = IsError;
        }
    }
}